package simpleTaskBoard.dto;

import java.io.Serializable;

import simpleTaskBoard.entities.HistoryEntity;
import simpleTaskBoard.enums.ActionChangeEnum;
import ch.ivyteam.ivy.scripting.objects.DateTime;

public class HistoryDTO implements Serializable{
	
	/**
	 * 
	 */
	private static final long serialVersionUID = -3052708660637937284L;
	private long id;
	private DateTime dateChange;
	private String userChange;
	private ActionChangeEnum actionChange;
	private String fromChange;
	private String toChange;
	private TaskDTO task;
	
	public TaskDTO getTask() {
		return task;
	}
	public void setTask(TaskDTO task) {
		this.task = task;
	}
	public long getId() {
		return id;
	}
	public void setId(long id) {
		this.id = id;
	}
	public DateTime getDateChange() {
		return dateChange;
	}
	public void setDateChange(DateTime dateChange) {
		this.dateChange = dateChange;
	}
	public String getUserChange() {
		return userChange;
	}
	public void setUserChange(String userChange) {
		this.userChange = userChange;
	}
	public ActionChangeEnum getActionChange() {
		return actionChange;
	}
	public void setActionChange(ActionChangeEnum actionChange) {
		this.actionChange = actionChange;
	}
	public String getFromChange() {
		return fromChange;
	}
	public void setFromChange(String fromChange) {
		this.fromChange = fromChange;
	}
	public String getToChange() {
		return toChange;
	}
	public void setToChange(String toChange) {
		this.toChange = toChange;
	}
	
	public HistoryDTO(HistoryEntity history) {
		this.id = history.getId();
		this.dateChange = history.getDate();
		this.userChange = history.getUser();
		this.actionChange=ActionChangeEnum.valueOf(history.getAction());
		this.fromChange = history.getFrom();
		this.toChange = history.getTo();
		this.task= new TaskDTO(history.getTask());
	}
	
	public HistoryDTO(){
		
	}
	public HistoryEntity convertToEntity(HistoryDTO history){
		HistoryEntity historyEntity = new HistoryEntity();
		if(historyEntity.getId()!=null && historyEntity.getId()>0)
		{
			historyEntity.setId(history.getId());
		}
		historyEntity.setAction(history.getActionChange().name());
		historyEntity.setDate(history.getDateChange());
		historyEntity.setFrom(history.getFromChange());
		historyEntity.setTo(history.getToChange());
		historyEntity.setUser(history.getUserChange());
		TaskDTO taskDTO=history.getTask();
		historyEntity.setTask(taskDTO.convertToEntity(taskDTO));
		return historyEntity;
	}
}
